package com.cat.dataStructure;

import java.util.HashMap;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/minimum-consecutive-cards-to-pick-up/description/
 * @create 2025/8/14 08:50
 * @since JDK17
 */

public class Solution02 {
    static HashMap<Integer, Integer> map = new HashMap<>();

    public int minimumCardPickup(int[] cards) {
        map.clear();
        int n = cards.length, ans = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            if (map.containsKey(cards[i])) {
                ans = Math.min(i - map.get(cards[i]) + 1, ans);
            }
            map.put(cards[i], i);
        }

        return ans == Integer.MAX_VALUE ? -1 : ans;
    }
}
